package org.darkforest.controller;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.darkforest.dao.mapper.ActiveAreaGoodsMapper;
import org.darkforest.dao.mapper.GoodsCommonMapper;
import org.darkforest.model.ActiveAreaGoods;
import org.darkforest.model.EntityBase;
import org.darkforest.model.GoodsCommon;
import org.darkforest.model.RestEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 专区
 *
 * @auth bingo
 * @create 2017-11-21-16:19
 */
@RestController
@RequestMapping(value = "activeArea")
@Api(value = "activeArea", description = "品质生活",produces= MediaType.APPLICATION_JSON_VALUE)
public class ActiveAreaController {


    @Autowired
    private ActiveAreaGoodsMapper activeAreaGoodsMapper;

    @Autowired
    private GoodsCommonMapper goodsCommonMapper;

    /**
     * 爱心助力
     * 品质生活列表 精神家园 创意家居 珍特优鲜
     *
     * @param p
     * @return
     */
    @RequestMapping(value = "list",method = RequestMethod.POST)
    @ApiOperation(value = "品质生活列表:精神家园(jsjy) 创意家居(cyjj) 珍特优鲜(mtyx) 其他(qt); 爱心助力(axzl)", httpMethod = "POST",produces= MediaType.APPLICATION_JSON_VALUE)
    public RestEntity activeAreaList(@RequestParam(required = false, defaultValue = "1") Integer p,
                                     @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                       @RequestParam(required = false, defaultValue = "axzl") String recommendType,
                                       String goodsName) {
        try{
            ActiveAreaGoods activeAreaGoods= new ActiveAreaGoods(recommendType);
            activeAreaGoods.setStart(p);
            activeAreaGoods.setDisplay("1");
            activeAreaGoods.setState("1");
            activeAreaGoods.setPageSize(pageSize);
            activeAreaGoods.setGoodsName(StringUtils.isBlank(goodsName)?null:goodsName);
            List<ActiveAreaGoods> activeAreaGoodsList = activeAreaGoodsMapper.selectByCondition(activeAreaGoods);
            return RestEntity.success(activeAreaGoodsList);
        }catch (Exception e){
            e.printStackTrace();
            return RestEntity.failed();
        }
    }

}
